package com.unitd.modules.sys.controller;

import com.unitd.comm.web.BaseController;
import com.unitd.frame.springweb.helper.MailHelper;
import com.unitd.frame.sso.annotation.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Hudan
 * @version 1.0
 * @desc 邮件发送测试前端控制器类
 * @filename MailController.java
 * @copyright www.unitd.com
 * @date 2017/4/11
 */
@Controller
@RequestMapping("/sys/mail")
public class MailController extends BaseController {

	@Autowired
	private MailHelper mailHelper;

	/**
	 * @desc 发送邮件
	 * @param model MVC模型对象
	 * @param email 邮件内容
	 * @return
	 */
	@Permission("sys:mail:send")
	@RequestMapping("/send")
	public String send(Model model, String email) {
		if (isPost()) {
			model.addAttribute("email", email);
			model.addAttribute("loginName", getSSOToken().getData());
			boolean rlt = mailHelper.sendMail(email, "测试邮件发送！", "/com/unitd/server/sys/mail/tplSend.html", model);
			String tipMsg = "发送邮件至【" + email + "】失败！！";
			if (rlt) {
				tipMsg = "已成功发送邮件至【" + email + "】注意查收！！";
			}
			model.addAttribute("tipMsg", tipMsg);
		}
		return "/modules/sys/mail/send";
	}
}